package com.net.marketing.statementcreator;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.jdbc.core.PreparedStatementCreator;

import com.net.marketing.domain.MemberDetails;

/**
 *@Author pao quilala
 *@Date   Aug 8, 2012
 **/

public class UpdateMemberDetailsStatementCreator implements
		PreparedStatementCreator {
	private MemberDetails memberDetails;
	
	public UpdateMemberDetailsStatementCreator(
			MemberDetails memberDetails) {
		super();
		this.memberDetails = memberDetails;
	}

	public PreparedStatement createPreparedStatement(Connection con)
			throws SQLException {
		String sql = "UPDATE MC_EXCEPTIONS " +
				     "   SET FIRST_NAME=?, " +
                     "       MIDDLE_NAME=?, " +
                     "       LAST_NAME=?, " +
                     "       ADDRESS=?, " +
                     "       ZIPCODE=?, " +
                     "       CONTACT_NO=?, "+
                     "       BIRTHDATE=?, " +
                     "       AGE=?, " +
                     "       SEX=?, " +
                     "       STATUS=?, " +
                     "       NATIONALITY=?, " +				                        
                     " WHERE MEMBER_ID=?";				
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, this.memberDetails.getFirstName());		
		ps.setString(2, this.memberDetails.getMiddleName());	
		ps.setString(3, this.memberDetails.getLastName());
		ps.setString(4, this.memberDetails.getAddress());
		ps.setString(5, this.memberDetails.getZipCode());
		ps.setString(6, this.memberDetails.getContactNo());
		ps.setDate(7, (Date) this.memberDetails.getBirthDate());
		ps.setString(8, this.memberDetails.getAge());
		ps.setString(9, this.memberDetails.getSex());
		ps.setString(10, this.memberDetails.getStatus());
		ps.setString(12, this.memberDetails.getNationality());		
		ps.setLong(13, this.memberDetails.getMemberId());		
		return ps;
	}
}
